<?php
// SETTINGS
include("../../settings.inc.php");
    $table = new Tables;

// PHP
include("../../php/php.php");
    $php = new PHP;

// DATABASE
include("../../db/mysql.php");
    $db = new DB;
    // connect to the datbase
    $db->connect();

// SESSIONS
include("../../session/session.php");
    $session = new Session;
    $session->init();

// HTML
include("../../html/html.php");
    $html = new HTML;

// HTML FORMS
include("../../form/form.php");
    $html_form = new HTMLForm;

// COMMON HTML TEXT
include("../../common/common.php");
    $common = new Common;

$dir = $_GET['dir'];
#if ($dir == "") { $dir = "./"; }

?>

<html>
<head>
<META HTTP-EQUIV="Content-Type" content="text/html; charset=<?php echo $charset; ?>">
<style>
BODY {	MARGIN-TOP:00pt; MARGIN-BOTTOM:00pt; FONT-SIZE: 8pt; COLOR: #000000; FONT-FAMILY: Verdana,Arial,Tahoma; FONT-WEIGHT: normal; background-color:#ffffff; border-top:1pt solid; border-bottom:1pt solid; border-left:1pt solid; border-right:1pt solid }
P {	margin-top:0pt; margin-bottom:0pt;}
A:link {	COLOR: #0080c0; FONT-WEIGHT: normal; TEXT-DECORATION: underline}
A:visited {	COLOR: #0080c0; FONT-WEIGHT: normal; TEXT-DECORATION: underline}
A:active {	COLOR: #0080c0; FONT-WEIGHT: normal; TEXT-DECORATION: underline}
A:hover {	COLOR: #40c0ff; FONT-WEIGHT: normal; TEXT-DECORATION: underline}

TABLE { BORDER: 0pt }

TH { BACKGROUND-COLOR:#00486a; FONT-SIZE: 8pt; COLOR: #64b5db; FONT-FAMILY: Arial,Verdana,Tahoma; FONT-WEIGHT: bold}
TD { FONT-SIZE: 8pt; COLOR: #000000; FONT-FAMILY: Verdana,Arial,Tahoma; FONT-WEIGHT: normal}
TD.navmenu { FONT-SIZE: 7.5pt; COLOR: #000000; FONT-FAMILY: Verdana,Arial,Tahoma; FONT-WEIGHT: normal}
TD A:link {	   COLOR: #006595; FONT-WEIGHT: normal; TEXT-DECORATION: none}
TD A:visited { COLOR: #006595; FONT-WEIGHT: normal; TEXT-DECORATION: none}
TD A:active {  COLOR: #006595; FONT-WEIGHT: normal; TEXT-DECORATION: none}
TD A:hover {   COLOR: #64b5db; FONT-WEIGHT: normal; TEXT-DECORATION: underline}

.blue { COLOR: #0381d6; }
.1px_border { BORDER: 1pt #00486a SOLID; }
.menu,.menu A:link,.menu A:visited,.menu A:active,.menu A:hover { font-size:7.5pt; font-weight: bold }

FORM {	FONT-SIZE: 8pt; FONT-FAMILY: Verdana,Arial,Tahoma; MARGIN-TOP: 0pt; MARGIN-BOTTOM: 0pt }
INPUT,TEXTAREA,SELECT { COLOR: #00486a; FONT-SIZE: 8pt; FONT-FAMILY: Verdana,Arial,Tahoma; BORDER: #000000 1px solid; BACKGROUND-COLOR: #64b5db}
INPUT.checkbox { background:none; border:0pt; }
INPUT.radio { background:none; border:0pt; }
INPUT.submit { background-color:#006595; color:#ffffff }

INPUT.admin { background-color:#cccccc; font-family:Courier New,System; color:#000000; font-size:9pt }
TEXTAREA.admin { background-color:#cccccc; font-family:Courier New,System; color:#000000; font-size:9pt }
</style>
</head>
<script language=JavaScript>
function insertAtCaret (icon1, icon2) 
{ 
    if (window.parent.document.pagecreator.pagecontent.createTextRange && window.parent.document.pagecreator.pagecontent.caretPos) 
    { 
        var caretPos = window.parent.document.pagecreator.pagecontent.caretPos; 
        selectedtext = caretPos.text; 
        caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? icon1 : icon1; 
        caretPos.text = caretPos.text + selectedtext + icon2; 
    } 
    else window.parent.document.pagecreator.pagecontent.value = window.parent.document.pagecreator.pagecontent.value + icon1 + icon2;
    window.parent.document.pagecreator.pagecontent.focus();
	
	window.location = 'about:blank';
}
</script>
</body>
<?php

$content.= showDirContent($dir);


// Print Page
echo $content;

// FUNCTIONS


function showDirContent($dir)
{
    $str = "<a href='filetree.php'>ROOT</a>/";
	    $parts = explode("/", $dir); array_pop($parts);
		$act = "";
		foreach ($parts as $part)
		{
		    $act.= $part."/";
		    $str.= "<a href='filetree.php?dir=";
			$str.= "$act";
			$str.= "'>".$part."</a>/";
		}
		$str.= "<br>";
    $folder=opendir("../../".$dir);
	$directories = array();
	$images      = array();
	    while ($entry = readdir($folder))
		{
		    $name = $dir.$entry;
		    if (!eregi("^(\.|\.\.)$", $entry))
			{
		        if (is_dir("../../".$name)) { array_push($directories, $entry); }
			    elseif (eregi("(jpeg|jpg|gif|bmp|png)$", $name)) { array_push($images, $entry); }
			}
		}
	closedir($folder);
		asort ($directories); foreach ($directories as $i) { $str.=showDir($dir.$i, $i); }
		asort ($images); foreach ($images as $i) { $str.=showImageFile($dir, $i); }
	
	return $str;
}


function showDir($dir, $entry)
{
    $str = "<img src='../images/dir.gif' border='0'> ";
	$str.= "<a href='filetree.php?dir=$dir/'>$entry</a><br>";
	return $str;
}


function showImageFile($dir, $name)
{
	$str.= "<img src='../images/page.gif' border='0'> &nbsp;";
	$str.= "<a href=\"javascript:insertAtCaret('','=$dir$name')\">$name</a><br>";
	return $str;
}
?>
</body>
</html>